
import axios from 'axios'
import * as actionTypes from './actionTypes'
import {fromJS} from 'immutable'


export const toggleTopShow = (show) => ({
    type: actionTypes.TOGGLE_SCROLL_TOP,
    show 
})

const addHomeList = (list) => ({
    type: actionTypes.ADD_ARTICLE_LIST,
    list: fromJS(list)
})

export const getMoreList = () => {
    return (dispatch) => {
        axios.get('/api/home.json').then((res)=>{
            const result = res.data.data;
            dispatch(addHomeList(result.articleList)); // 执行非函数的action
        }) 
    }
}

const changeHomeData = (result) => ({
    type: actionTypes.CHANGE_HOME_DATA,
    topicList: result.topicList,
    articleList: result.articleList,
    recommendList: result.recommendList,
})

export const getHomeInfo = () => {
    return (dispatch) => {
        axios.get('/api/home.json').then((res)=>{
            const result = res.data.data;
            // const action = {
                // type: 'change_home_data',
                // topicList: result.topicList,
                // articleList: result.articleList,
                // recommendList: result.recommendList,
            // }
            dispatch(changeHomeData(result)); // 执行非函数的action
        }) 
    }
}